package com.baosight.sczx.zm.cs.service;

import java.util.ArrayList;
import java.util.List;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ef.ui.tree.TreeConstants;
import com.baosight.iplat4j.ef.ui.tree.TreeService;
import com.baosight.iplat4j.ep.QueryMap;
import com.baosight.sczx.common.zm.cInterface.cs.Engineering;
import com.baosight.sczx.common.zm.cInterface.cs.EngineeringDesign;
import com.baosight.sczx.common.zm.cInterface.cs.Mine;
import com.baosight.sczx.common.zm.cInterface.cs.OtherDesign;
import com.baosight.sczx.common.zm.cInterface.cs.RoadWay;
import com.baosight.sczx.common.zm.cInterface.cs.WorkingFace;

/**
 * <p>Title: ServiceZMCS60.java</p>
 * <p>Description: 工程建模-树的服务类</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张小飞
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-7 下午01:16:29  张小飞  Create
 *</pre>
 */
public class ServiceZMCS60 extends TreeService {

	@SuppressWarnings("rawtypes")
	@Override
	/**
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15上午11:14:45 路涛
	 * </p>
	 *
	 */
	public EiInfo query(EiInfo inInfo) {
		QueryMap queryInfo = QueryMap.getQueryMap(inInfo);
		String p = (String) queryInfo.get(TreeConstants.TREE_NODE);
		List children = new ArrayList();
		if (p == null) {
			p = "$";
		}
		if ("$".equals(p)) {
			children = this.getTopNodes();
		} else {
			children = this.getChildNode(queryInfo);
		}

		EiInfo outInfo = new EiInfo();
		EiBlock block = outInfo.addBlock(p);
		block.setBlockMeta(initMetaData());
		block.setRows(children);
		return outInfo;
	}
	
	/**获取子节点
	 * <p>Function: getChildNode</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15上午11:14:45 路涛
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unused" })
	public List getChildNode(QueryMap queryInfo) {
		
		String isLeaf = (String)queryInfo.get("isLeaf");//isLeaf level nodeTypes  node
		String fdKeyId = (String)queryInfo.get(TreeConstants.TREE_NODE);
		String level = (String)queryInfo.get("level");//1级节点  2级节点  3级节点
		String nodeTypes = (String)queryInfo.get("nodeTypes");//类型: 0工程设计  1工作面 2巷道  3其他 4工程
		
		List list = new ArrayList();
		
		//叶子节点
		if(isLeaf.equals("1")) {

		}
		
		//非叶子节点
		else {
			nodeTypes = nodeTypes == null ? "" : nodeTypes;
			
			//工程设计
			if(nodeTypes.equals("0")) {
				list = EngineeringDesign.getEngineeringModelTreeByMineId(fdKeyId);
			}
			//工作面
			else if(nodeTypes.equals("1")) {
				list = WorkingFace.getEngineeringModelTreeById(fdKeyId);
			}
			//巷道
			else if(nodeTypes.equals("2")) {
				list = RoadWay.getEngineeringModelTreeById(fdKeyId);
			}
			//其他
			else if(nodeTypes.equals("3")) {
				list = OtherDesign.getEngineeringModelTreeById(fdKeyId);
			}
			//工程
			else {
				list = Engineering.getEngineeringModelTreeById(fdKeyId);
			}
		}
		
		return list;
	}
	
	/**
	 * <p>Function: getChildNodes</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15上午11:14:45 路涛
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes" })
	@Override
	public List getChildNodes(String arg0) {
		return null;
	}

	/**
	 * 获取树根节点，从矿井信息表中
	 * <p>Function: getTopNodes</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15上午11:14:45 路涛
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public List getTopNodes(){
		return Mine.getRootForDesignTree();//获取矿井节点
	}

	/**
	 * <p>Function: initMetaData</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCS92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15上午11:14:45 路涛
	 * </p>
	 *
	 */
	@Override
	public EiBlockMeta initMetaData() {
		EiBlockMeta eiMetadata = new EiBlockMeta();

		EiColumn eiColumn = new EiColumn("display");
		eiColumn.setDescName("显示名称");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);

		eiColumn = new EiColumn("value");
		eiColumn.setDescName("KEYID");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("level");
		eiColumn.setDescName("树的节点");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("nodeTypes");
		eiColumn.setDescName("节点类型");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("tableName");
		eiColumn.setDescName("表名");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("number");
		eiColumn.setDescName("编号");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("isLeaf");
		eiColumn.setDescName("是否叶子节点");
		eiColumn.setType(EiConstant.COLUMN_TYPE_NUMBER);
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		eiColumn = new EiColumn("engineeringType");
		eiColumn.setDescName("工程类型");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		return eiMetadata;
	}

}
